<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户昵称" prop="nickname">
      <el-input v-model="dataForm.nickname" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="订单编号" prop="receiptcode">
      <el-input v-model="dataForm.receiptcode" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="customername">
      <el-input v-model="dataForm.customername" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="发送时间" prop="sendtime">
      <el-input v-model="dataForm.sendtime" placeholder="" disabled="disabled"></el-input>
    </el-form-item>
    <el-form-item label="回复内容" prop="recontent">
      <el-input v-model="dataForm.recontent" placeholder="" ></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" :disabled="subable" v-show="dataForm.isreply !== 1" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        subable: false,
        visible: false,
        dataForm: {
          id: 0,
          nickname: '',
          receiptcode: '',
          customername: '',
          phone: '',
          sendtime: '',
          isreply: '',
          recontent: '',
          retime: '',
          reuser: ''
        },
        dataRule: {
          recontent: [
            { required: true, message: '回复内容不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.subable = false
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/goodnotice/goodnotice/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.nickname = data.goodnotice.nickname
                this.dataForm.receiptcode = data.goodnotice.receiptcode
                this.dataForm.customername = data.goodnotice.customername
                this.dataForm.phone = data.goodnotice.phone
                this.dataForm.sendtime = data.goodnotice.sendtime
                this.dataForm.isreply = data.goodnotice.isreply
                this.dataForm.recontent = data.goodnotice.recontent
                this.dataForm.retime = data.goodnotice.retime
                this.dataForm.reuser = data.goodnotice.reuser
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.subable = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/goodnotice/goodnotice/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'recontent': this.dataForm.recontent
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          } else {
            this.subable = false
          }
        })
      }
    }
  }
</script>
